package com.haha.helloworld.fragment;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.haha.helloworld.R;

public class ContainerActivity extends AppCompatActivity implements AFragment.IOnMessageClick {
    //定义一个我们写的Fragment
    private AFragment aFragment;
    private BFragment bFragment;
    private Button btn_change;
    private TextView tv_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_container);
        tv_title=(TextView)findViewById(R.id.tv_title);
        //实例化AFragment
        aFragment=new AFragment();
        //把aFragment添加到ContainerActivity中的fl_container中,记得commit一下
        //其实也就是把自己定义的Fragment页面，放到其他页面中的FragmentLayout中去
        //设置一个tag为a
        getSupportFragmentManager().beginTransaction().add(R.id.fl_container,aFragment,"a").commitNowAllowingStateLoss();

    }
    //给tv_title赋值
    public void setData(String text){
        tv_title.setText(text);

    }

    //Afragment中的接口实现
    @Override
    public void onClick(String text) {
        tv_title.setText(text);
    }
}